package com.wsjzzcbq.qianyuan.sys.controller;

import com.wsjzzcbq.qianyuan.common.bean.PageBean;
import com.wsjzzcbq.qianyuan.common.bean.R;
import com.wsjzzcbq.qianyuan.sys.param.AddQuartzJobParam;
import com.wsjzzcbq.qianyuan.sys.param.FindQuartzJobParam;
import com.wsjzzcbq.qianyuan.sys.param.TriggerJobParam;
import com.wsjzzcbq.qianyuan.sys.service.QuartzJobService;
import com.wsjzzcbq.qianyuan.sys.vo.QuartzJobVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * SysQuartzJobController
 *
 * @author wsjz
 * @date 2022/03/22
 */
@RequestMapping("/sys/quartz/job")
@RestController
public class SysQuartzJobController {

    @Autowired
    private QuartzJobService quartzJobService;

    /**
     * 查询分页数据
     * @param param
     * @return
     */
    @GetMapping("/findList")
    public R<PageBean<QuartzJobVo>> findList(FindQuartzJobParam param) {
        return quartzJobService.findList(param);
    }

    /**
     * 添加任务
     * @param param
     * @return
     */
    @PostMapping("/addOrUpdate")
    public R<?> addOrUpdate(@RequestBody @Valid AddQuartzJobParam param) {
        return quartzJobService.addOrUpdate(param);
    }

    @DeleteMapping("/deleteJob")
    public R<?> deleteJob(String id) {
        return quartzJobService.deleteJob(id);
    }

    @PostMapping("/trigger")
    public R<?> triggerJob(@RequestBody @Valid TriggerJobParam param) {
        return quartzJobService.triggerJob(param);
    }

    @PostMapping("/resume")
    public R<?> resumeJob(@RequestBody @Valid TriggerJobParam param) {
        return quartzJobService.resumeJob(param);
    }

    @PostMapping("/pause")
    public R<?> pauseJob(@RequestBody @Valid TriggerJobParam param) {
        return quartzJobService.pauseJob(param);
    }
}
